<?php
//templates for VRML shapes

function onto_Thing($name){
  if ($name == "")
    die("onto_Thing: Empty name");
  $s = "#VRML V2.0 utf8\n".
  "Transform {\n".
  "    translation 0 20 0\n".
  "        children [\n".
  "            Shape {\n".
  "                appearance Appearance {\n".
  "    			    material Material {\n".
  "        				ambientIntensity 	0.95\n".
  "        				diffuseColor     	0.99 0.21 0.21\n".
  "        				specularColor    	0.3 0.3 0.3\n".
  "        				emissiveColor    	0 0 0\n".
  "        				shininess        	0.3\n".
  "        				transparency     	0\n".
  "        			}\n".
  "    	    	}\n".
  "                geometry Cone {\n".
  "                    bottomRadius 1\n".
  "                    height 2\n".
  "                    side TRUE\n".
  "                }\n".
  "			}\n".
  
  "			Transform {\n".
  "				translation 0 2 0\n".
  "				children [\n".
  "				    Billboard{\n".
  "                        children[\n".
  "                			 Text{\n".
  "                					string \"".$name."\"\n".
  "                					fontStyle FontStyle{\n".
  "                						justify \"MIDDLE\"\n".
  "                	        			style \"ITALIC\"\n".
  "                					}\n".
  "                			 }\n".
  "                		]\n".
  "                	}\n".
  "			]\n".
  "        }\n".
  "    ]\n".
  "}\n";
return $s;
};

function onto_Class($name, $id, $x, $y, $z){
  if ($name == "")
    die("onto_Class: Empty name");
  if (!isset($id))
    die("onto_Class: Bad id");
  if ((!isset($x)))
    die("onto_Class: Bad x:".$x);
  if ((!isset($y)))
    die("onto_Class: Bad y");
  if ((!isset($z)))
    die("onto_Class: Bad z");
    
  $s = "\n".
  "        Transform {\n".
  "            translation ".$x." ".$y." ".$z."\n".
  "                children [\n".
  "                    Shape {\n".
  "                        appearance Appearance {\n".
  "            			    material Material {\n".
  "                				ambientIntensity 	0.95\n".
  "                				diffuseColor     	0.21 0.91 0.21\n".
  "                				specularColor    	0.3 0.3 0.3\n".
  "                				emissiveColor    	0 0 0\n".
  "                				shininess        	0.3\n".
  "                				transparency     	0\n".
  "                			}\n".
  "            	    	}\n".
  "                        geometry Cylinder {\n".
  "                            radius 1\n".
  "                            height 2\n".
  "                            top TRUE\n".
  "                        }\n".
  "        			}\n".
  "                   DEF Clicker".$id." TouchSensor {}\n".
  
  "                   LOD {\n".
  "                       range [\n".
  "                          100\n".
  "                       ]\n".
  "                       center ".$x." ".$y." ".$z."\n".
  "                       level [\n".
  "                			Transform {\n".
  "                				translation 0 2 0\n".
  "                				children [\n".
  "                                    Billboard{\n".
  "                                        children[\n".
  "                                			 Text{\n".
  "                                					string \"".$name."\"\n".
  "                                					fontStyle FontStyle{\n".
  "                                						justify \"MIDDLE\"\n".
  "                                	        			style \"ITALIC\"\n".
  "                                					}\n".
  "                                			}\n".
  "                                		]\n".
  "                                	}\n".
  "                    			]\n".
  "                            }\n".
  "                            Transform {\n".
  "                               translation 0 2 0\n".
  "                				children [\n".
  "                                    Billboard{\n".
  "                                        children[\n".
  "                                			 DEF Result".$id." Text{\n".
  "                                					string \"\"\n".
  "                                					fontStyle FontStyle{\n".
  "                                						justify \"MIDDLE\"\n".
  "                                	        			style \"ITALIC\"\n".
  "                                					}\n".
  "                                			}\n".
  "                                		]\n".
  "                                	}\n".
  "                    			]\n".
  "                            }\n".
  "                       ]\n".
  "                   }\n".
  "             ]\n".
  "        }\n".
  "        DEF My_script".$id." Script {\n".
  "        eventIn SFTime My_Time\n".
  "        eventOut MFString My_String\n".
  "        url \"javascript:\n".
  "            function My_Time() {\n".
  "                if (My_String[0] == '')\n".
  "                    My_String[0] = '".$name."';\n".
  "                else\n".
  "                    My_String[0] = '';\n".
  "            }\n".
  "        \"\n".
  "        ROUTE Clicker".$id.".touchTime TO My_script".$id.".My_Time\n".
  "        ROUTE My_script".$id.".My_String TO Result".$id.".string\n".
  "}";
return $s;
};

function onto_Attributes($name, $id, $x, $y, $z, $r, $g, $b){
  if ($name == "")
    die("onto_Attributes: Empty name");
  if ((!isset($id)) or ($id <= 0))
    die("onto_Attributes: Bad id");
  if ((!isset($x)))
    die("onto_Attributes: Bad x");
  if ((!isset($y)))
    die("onto_Attributes: Bad y");
  if ((!isset($z)))
    die("onto_Attributes: Bad z");
  $s = "\n".
  "        Transform {\n".
  "            translation ".$x." ".$y." ".$z."\n".
  "                children [\n".
  "                    Shape {\n".
  "                        appearance Appearance {\n".
  "            			    material Material {\n".
  "                				ambientIntensity 	0.95\n".
  //"                				diffuseColor     	0.10 0.50 0.9\n".
  "                				diffuseColor     	".$r." ".$g." ".$b."\n".
  "                				specularColor    	0.3 0.3 0.3\n".
  "                				emissiveColor    	0 0 0\n".
  "                				shininess        	0.3\n".
  "                				transparency     	0\n".
  "                			}\n".
  "            	    	}\n".
  "                        geometry Sphere {\n".
  "                            radius 0.8\n".
  "                        }\n".
  "                    }\n".
  "                    DEF Clicker_attr".$id." TouchSensor {}\n".
  
  "                    LOD {\n".
  "                       range [\n".
  "                          100\n".
  "                       ]\n".
  "                       center ".$x." ".$y." ".$z."\n".
  "                       level [\n".
  "                			Transform {\n".
  "                				translation 0 1 0\n".
  "                				children [\n".
  "                    				Billboard{\n".
  "                    				    children[\n".
  "                                			 Text{\n".
  "                                					string \"".$name."\"\n".
  "                                					fontStyle FontStyle{\n".
  "                                						justify \"MIDDLE\"\n".
  "                                	        			style \"ITALIC\"\n".
  "                                					}\n".
  "                                			}\n".
  "                                		]\n".
  "                                    }\n".
  "                    			]\n".
  "                            }\n".
  "                            Transform{\n".
  "                               translation 0 2 0\n".
  "                				children [\n".
  "                                    Billboard{\n".
  "                                        children[\n".
  "                                			 DEF Result_attr".$id." Text{\n".
  "                                					string \"\"\n".
  "                                					fontStyle FontStyle{\n".
  "                                						justify \"MIDDLE\"\n".
  "                                	        			style \"ITALIC\"\n".
  "                                					}\n".
  "                                			}\n".
  "                                		]\n".
  "                                	}\n".
  "                    			]\n".
  "                            }\n".
  "                       ]\n".
  "                   }\n".
  "             ]\n".
  "        }\n".
  "        DEF My_script_attr".$id." Script {\n".
  "        eventIn SFTime My_Time\n".
  "        eventOut MFString My_String\n".
  "        url \"javascript:\n".
  "            function My_Time() {\n".
  "                if (My_String[0] == '')\n".
  "                    My_String[0] = '".$name."';\n".
  "                else\n".
  "                    My_String[0] = '';\n".
  "            }\n".
  "        \"\n".
  "        ROUTE Clicker_attr".$id.".touchTime TO My_script_attr".$id.".My_Time\n".
  "        ROUTE My_script_attr".$id.".My_String TO Result_attr".$id.".string\n".
  "}\n";
return $s;
};

function onto_relationship($string, $id, $color){
  $s = "\n".
  "        DEF relation".$id." Shape{\n".
  "           geometry IndexedLineSet{\n".
  "               coord Coordinate {point [".$string."]}\n".
  "               coordIndex[0 1 -1]\n".
  "               color Color {\n".
  "                   color [".$color." ".$color."]\n".
  "               }\n".
  "               colorIndex[]\n".
  "           }\n".
  "        }\n";
return $s;
};

function onto_viewpoints($viewpoints){
  $s = '';
  for ($i = 0; $i < count($viewpoints); $i++){
      $s .= "DEF view".$viewpoints[$i]->id." Viewpoint {\n".
           "    position ".$viewpoints[$i]->x." ".$viewpoints[$i]->y." ".(($viewpoints[$i]->z)+15)."\n".
           "    orientation	0 0 1 0\n".
           "    fieldOfView	0.785398\n".
           "     description	\"".$viewpoints[$i]->name."\"\n".
           "   }\n";
  };
  return $s;
};

function onto_LOD($x, $y, $z, $lod){
  if ((!isset($x)))
    die("onto_LOD: Bad x - ".$x);
  if ((!isset($y)))
    die("onto_LOD: Bad y");
  if ((!isset($z)))
    die("onto_LOD: Bad z");
  if ((!isset($lod)) or ($lod <= 0))
    die("onto_LOD: Bad lod");
  $s = "\n".
  "LOD {\n".
  "   range [\n".
  "      ".$lod."\n".
  "   ]\n".
  "   center ".$x." ".$y." ".$z."\n".
  "   level [\n".
  "        Transform{\n".
  "            children[\n";
return $s;
};

function onto_endLOD(){
  $s = "\n".
  "            ]\n".
  "        }\n".
  "        Transform {\n".
  "        }\n".
  "   ]\n".
  "}\n";
return $s;
};

?>